/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package operators;

import metadata.TableMetaData;

/**
 *
 * @author Dragan
 */
public class TidIntersection extends Operation {

    TableMetaData masterTable;
    TableMetaData[] tables;
    long[] inputs;

    public TidIntersection(TableMetaData masterTable, TableMetaData[] tables, long[] inputs) {
        if (tables.length != inputs.length) {
            throw new IllegalArgumentException("There must be equal number of tables and inputs");
        }
        this.masterTable = masterTable;
        this.tables = tables;
        this.inputs = inputs;
        this.operationName = "TidIntersection";
        execute();
    }

    @Override
    protected void execute() {
        this.diskCost = 0;
        double output = masterTable.getNumberOfTuples();
        for (long input : inputs) {
            output *= (input / (double) masterTable.getNumberOfTuples());
        }
        this.outputSize = (long) output;
    }

    @Override
    public String toString() {
        String str = "";
        str += this.getOperationName();
        int i = 0;
        for (TableMetaData tmd : tables) {
            str += " t:" + (i + 1) + "" + tmd.getTableName() + " input:" + inputs[i++];
        }
        return str + super.toString();
    }
}
